package com.evon.yardmanagement.ui.action.transaction;

import java.util.ArrayList;
import java.util.List;

import com.evon.yardmanagement.model.Member;
import com.evon.yardmanagement.service.MemberService;
import com.evon.yardmanagement.ui.dto.MemberDTO;
import com.opensymphony.xwork2.ActionSupport;

public class AssignDriverAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private List<MemberDTO> availableMembers = new ArrayList<MemberDTO>();

	private int selectedMemberId;

	private int yardId;

	public List<MemberDTO> getAvailableMembers() {
		return availableMembers;
	}

	public void setAvailableMembers(List<MemberDTO> availableMembers) {
		this.availableMembers = availableMembers;
	}

	public int getSelectedMemberId() {
		return selectedMemberId;
	}

	public void setSelectedMemberId(int selectedMemberId) {
		this.selectedMemberId = selectedMemberId;
	}

	public int getYardId() {
		return yardId;
	}

	public void setYardId(int yardId) {
		this.yardId = yardId;
	}

	public String init() {
		availableMembers = new MemberService().getUnOccupiedMembersOfYard(yardId);
		if (availableMembers != null && !availableMembers.isEmpty()) {
			selectedMemberId = availableMembers.get(0).getId();
		}
		return SUCCESS;
	}

	public String execute() {
		return SUCCESS;
	}
}
